//
//  GoodsCycleImageCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/8.
//  Copyright © 2017年 beisheng. All rights reserved.
//GoodsDetailMidCell

#import "GoodsCycleImageCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>

@interface GoodsCycleImageCell ()<SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topMargin;
@property (nonatomic, weak) SDCycleScrollView *cycleView;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;

@property (weak, nonatomic) IBOutlet UILabel *wineNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *leftPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightPriceLabel;

@end

@implementation GoodsCycleImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.wineNameLabel.font = MYFONT(17);
    
    self.leftPriceLabel.font = MYFONT(15);
    
    self.rightPriceLabel.font = MYFONT(15);
    
    self.bottomMargin.constant = 5;


    
    [self setupTopScrollview];
}



- (void)setupTopScrollview{
    
    if (!_cycleView) {
        // 网络加载 --- 创建自定义图片的pageControlDot的图片轮播器
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KScreenW, KScreenW / 8.0 * 3) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        cycleScrollView.autoScrollTimeInterval = 3;
        cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        //    cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
        //    cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
        _cycleView = cycleScrollView;
        
        
        [self.bgView addSubview:_cycleView];
        
        
    }
    
    
}


- (void)setModel:(GoodsDetailModel *)model{
    _model = model;
    
    self.cycleView.imageURLStringsGroup = _model.img_list;
    
    UIImage *tempImage = [[[SDWebImageManager sharedManager]imageCache]imageFromDiskCacheForKey:_model.img_list.firstObject];
    
    if (tempImage != nil) {
        
        self.bgViewH.constant = KScreenW/tempImage.size.width * tempImage.size.height;
        
        self.cycleView.height = self.bgViewH.constant;
        
        NSLog(@"%f",self.cycleView.height);
        
    } else {
        
        self.bgViewH.constant = 414;
        
        self.cycleView.height = 414;
        
    }
    
   
    
    self.wineNameLabel.text = _model.goods_name;
    
    
    self.leftPriceLabel.text = [NSString stringWithFormat:@"%@P",_model.price];
    
    
}


- (NSMutableAttributedString *)attributedStrin:(NSString *)str{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:MYFONT(14) range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:darkGray range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSStrikethroughStyleAttributeName value:@1 range:NSMakeRange(0, str.length)];
    //    [attr addAttribute:NSKernAttributeName value:@(0.5f) range:NSMakeRange(0, str.length)];
    
    return attr;
}





#pragma mark - SDCycleScrollViewDelegate

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
